<%@ page language="java" contentType="text/html; charset=UTF-8"  
    pageEncoding="UTF-8"%>  
<%@page import="java.io.*"%>  
<%@page import="javax.swing.filechooser.*"%>  
<!DOCTYPE>  
<html>  
<head>  
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">  
<title>创建网站桌面快捷键</title>  
</head>  
<body>  
  
<%  
	request.setCharacterEncoding("UTF-8");
	String url = request.getParameter("url").trim();  //必须是决定路径
	String web_name = request.getParameter("realfilename").trim();	
	 web_name=new String(web_name.getBytes("ISO-8859-1"),"UTF-8");
	
	if(null!=url && !"".equals(url)){
		
	}else{
		url = request.getScheme() + "://" + request.getServerName()+request.getContextPath();
	}
	
	if(null!=web_name && !"".equals(web_name)){
		
	}else{
		web_name ="网站快捷键";
	}
	
	//System.out.println(url);
	//System.out.println(web_name);
    String templateContent = "[InternetShortcut]" + "\n" + "URL= "+url;   
    String realfilename = web_name + ".url";     
    FileSystemView fsv = FileSystemView.getFileSystemView();      
    String upurl = fsv.getHomeDirectory().toString();     
    //System.out.println(upurl);     
    String filename = upurl + "/" + realfilename;     
    File myfile = new File(filename);     
    if(!myfile.exists()){  
        FileOutputStream fileoutputstream = new FileOutputStream(filename);//建立文件输出流      
        byte tag_bytes[] = templateContent.getBytes();     
        fileoutputstream.write(tag_bytes);     
        fileoutputstream.close();     
    }  
    try {     
        File file = new File(upurl, realfilename);     
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));     
        byte[] buffer = new byte[111000];     
        realfilename = java.net.URLEncoder.encode(realfilename,     
        "UTF-8");     
        response.reset();     
        response.setCharacterEncoding("UTF-8");     
        response.setContentType("application/x-download");//不同类型的文件对应不同的MIME类型     
        response.setHeader("Content-Disposition",     
        "attachment; filename=" + realfilename);     
        OutputStream os = response.getOutputStream();     
        while (bis.read(buffer) > 0) {     
            os.write(buffer);     
        }     
        bis.close();     
        os.close();     
        out.clear();     
        out=pageContext.pushBody();     
    } catch (Exception e) {     
        e.printStackTrace();     
    }   
	
  
%>  
  
</body>  
</html>  